package com.oa.utils;

import java.io.*;

public class FileUtils {


    public static boolean writeFile(File file, File targetFile) {
        InputStream is = null;
        FileOutputStream fos = null;
        try {
            is = new FileInputStream(file);
            fos = new FileOutputStream(targetFile);
            byte[] b = new byte[1024 * 1];
            int hasread = 0;
            while ((hasread = is.read(b)) != -1) {
                fos.write(b, 0, hasread);
            }
            fos.flush();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (fos != null) {
                try {
                    fos.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (is != null) {
                try {
                    is.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        return true;
    }

    public static boolean deleteFile(String path){
        File lafile = new File(path);
        if (lafile.exists()) {
            lafile.delete();
        }
        return true;
    }


}
